package com.lglin.dao.admin;

import com.lglin.bean.product.entity.Category;
import com.lglin.bean.product.entity.Product;
import com.lglin.bean.user.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface AdminDao {

    @Select("select * from user a join user_role b on a.id = b.uid and b.rid=2")
    List<User> selectUser();

    List<User> searchUser(Map<String, String> map);

    @Update("update user set password=#{password},nickname=#{nickname} WHERE id=#{id}")
    int updateUserInfo(User user);

    int deleteUser(String ids);

    @Select("select o.id, o.sid, o.time, a.consignee, os.status, sum(op.num*p.old_price) as old_price, sum(op.num*p.new_price) as new_price from `order` o join address a on o.aid = a.id join order_status os on os.id = o.osid join order_product op on op.oid = o.id join product p on op.pid = p.id group by op.oid")
    List<Map<String, Object>> orderList();

    @Select("select o.oid, o.num, p.old_price, p.new_price from order_product o join product p on o.pid = p.id")
    List<Map<String, Object>> getProduct();

    int deleteOrder(String ids);

    List<Map<String, Object>> searchOrder(Map<String, String> map);

    List<Map<String, Object>> searchProduct(String key);

    @Insert("insert into product (name, num, old_price, new_price, brief_intro, detail, is_new, stock) values (#{name}, #{num}, #{old_price}, #{new_price}, #{brief_intro}, #{detail}, #{is_new}, #{stock})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addProduct(Map<String, Object> map);

    int addProductCategory(@Param("pid") int pid, @Param("cids") int[] cids);

    @Select("select * from category where flag != 3")
    List<Category> getCategory();

    @Select("select * from product where id = #{id}")
    Map<String, Object> getProductInfo(int id);

    int updateProduct(Map<String, Object> map);

    @Delete("delete from product where id = #{id}")
    int deleteProduct(int id);

    @Delete("delete from product_category where pid = #{id}")
    int deleteProductCategry(int id);

    @Delete("delete from category where id = #{id}")
    int deleteCategory(int id);

    @Insert("insert into category (name, flag) values (#{name}, 2)")
    int addCategory(String name);

    int addPic(@Param("id") int id, @Param("paths") String[] path);

    @Update("update `order` set osid = #{status} where id = #{id}")
    int updateOrderStatus(@Param("id") int id, @Param("status") int status);
}
